﻿<template>
	<transition name="el-zoom-in-center">
		<div class="SHZY-preview-main">
			<div class="SHZY-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : '编辑'" />
				<div class="options">
			
					<el-button type="success" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
					<el-button type="danger" @click="goBack">关 闭</el-button>
				</div>
			</div>
			<div :style="{ margin: '0 auto', width: '100%' }">
				<el-row :gutter="15" class="" style="margin-top: 10px;">
					<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right"
						:rules="rules">
						<el-col :span="6">
							<el-form-item label="条码" prop="barcode">
								<el-input v-model='dataForm.barcode' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="做番号 " prop="no">
								<el-input v-model='dataForm.no' placeholder='请输入' clearable :style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="单位名称" prop="name">
								<el-input v-model='dataForm.name' placeholder='请输入' clearable :style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="产品型号" prop="model">
								<el-input v-model='dataForm.model' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="箱号" prop="boxNo">
								<el-input v-model='dataForm.boxNo' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="箱名" prop="boxName">
								<el-input v-model='dataForm.boxName' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="图号" prop="drawingNo">
								<el-input v-model='dataForm.drawingNo' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="部件名称" prop="componentName">
								<el-input v-model='dataForm.componentName' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="规格" prop="specifications">
								<el-input v-model='dataForm.specifications' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="单位" prop="unit">
								<el-input v-model='dataForm.unit' placeholder='请输入' clearable :style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="数量" prop="qty">
								<el-input v-model='dataForm.qty' placeholder='请输入' clearable :style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="备注" prop="remark">
								<el-input v-model='dataForm.remark' placeholder='请输入' clearable
									:style='{ "width": "100%" }'>
								</el-input>
							</el-form-item>
						</el-col>
						<el-col :span="6">
							<el-form-item label="打印时间" prop="printDate">
								<el-date-picker v-model='dataForm.printDate' placeholder='请选择' clearable
									:style='{ "width": "100%" }' type='date' format='yyyy-MM-dd'
									value-format='timestamp'>
								</el-date-picker>
							</el-form-item>
						</el-col>
					</el-form>
				</el-row>
			</div>
		</div>
	</transition>
</template>
<script>
import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { getDataInterfaceRes } from '@/api/systemData/dataInterface'
export default {
	components: {},
	props: [],
	data() {
		return {
			btnLoading: false,
			loading: false,
			visible: false,
			dataForm: {
				id: '',
				barcode: undefined,
				no: undefined,
				name: undefined,
				model: undefined,
				boxNo: undefined,
				boxName: undefined,
				drawingNo: undefined,
				componentName: undefined,
				specifications: undefined,
				unit: undefined,
				qty: undefined,
				remark: undefined,
				printDate: undefined,
			},
			rules: {
			},
		}
	},
	computed: {},
	watch: {},
	created() {
	},
	mounted() {
	},
	methods: {
		goBack() {
			this.$emit('refresh')
		},
		init(id) {
			this.dataForm.id = id || 0;
			this.visible = true;
			this.$nextTick(() => {
				this.$refs['elForm'].resetFields();
				if (this.dataForm.id) {
					request({
						url: '/api/Business/QmsBusiPickRecord/' + this.dataForm.id,
						method: 'get'
					}).then(res => {
						this.dataForm = res.data;
					})
				}
			});
			this.$store.commit('generator/UPDATE_RELATION_DATA', {})
		},
		dataFormSubmit() {
			this.$refs['elForm'].validate((valid) => {
				if (valid) {
					this.btnLoading = true;
					if (!this.dataForm.id) {
						request({
							url: `/api/Business/QmsBusiPickRecord`,
							method: 'post',
							data: this.dataForm,
						}).then((res) => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.btnLoading = false;
									this.visible = false,
										this.$emit('refresh', true)
								}
							})
						})
					} else {
						request({
							url: '/api/Business/QmsBusiPickRecord/' + this.dataForm.id,
							method: 'PUT',
							data: this.dataForm
						}).then((res) => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.btnLoading = false;
									this.visible = false
									this.$emit('refresh', true)
								}
							})
						})
					}
				}
			})
		},
	}
}
</script>
